package cn.edu.neusoft.food229.model;

import java.util.List;

import cn.edu.neusoft.food229.bean.Collect;
import cn.edu.neusoft.food229.iface.CollectListiface;
import cn.edu.neusoft.food229.listener.CollectListListener;
import cn.edu.neusoft.food229.service.CollectService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static cn.edu.neusoft.food229.Commen.Commen.BASEURL;

public class CollectListModel implements CollectListiface {
    private Retrofit retrofit;
    public CollectListModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void collectList( String user_id, int flag,final CollectListListener listener) {
        CollectService service=retrofit.create(CollectService.class);
        Call<List<Collect>> call=service.collectList(user_id, flag);
        call.enqueue(new Callback<List<Collect>>() {
    @Override
    public void onResponse(Call<List<Collect>> call, Response<List<Collect>> response) {
        if(response.isSuccessful() && response!=null){
            listener.onResponce(response.body());
        }
        else listener.onFail("on response fail");
    }

    @Override
    public void onFailure(Call<List<Collect>> call, Throwable t) {
        listener.onFail(t.toString());
    }
});



    }


}
